package com.ydche.util;
import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class PinyinCodeUtil {
    private static Logger log = LogManager.getLogger(PinyinCodeUtil.class);
    /**
     * 获取拼音码
     * @param name
     * @return
     */
    public static String getPinyinCode(String name){
        String pinyinCode = "#";
        if(!StringUtil.isNULLorEmpty(name)){
            try {
                Character cha = PinyinHelper.getShortPinyin(name).charAt(0);
                if(Character.isLetter(cha)){
                    pinyinCode = String.valueOf(cha).toUpperCase();
                }
            } catch (PinyinException e) {
                log.warn("getPinyinCode() name="+ name +", warn:"+ e);
            }
        }
        return pinyinCode;
    }



}
